package com.prd.controller;


import com.prd.dto.SysUserDTO;
import com.prd.service.SysUserService;
import com.prd.util.JsonData;
import com.prd.vo.LoginUserVo;
import com.prd.web.controller.BaseController;
import com.prd.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * <p>
 * 系统用户数据表 前端控制器
 * </p>
 *
 * @author lizhaoyi
 * @since 2024-01-09
 */
@RestController
@RequestMapping("/api/sysUser")
@Api(tags = "用户管理")
public class SysUserController extends BaseController {

    @Autowired
    private SysUserService sysUserService;


    @ApiOperation("同步用户信息")
    @PostMapping("syncUserInfo")
    public JsonData syncUserInfo(){

        return sysUserService.syncUserInfo();
    }

    @ApiOperation("获取用户列表")
    @PostMapping("list")
    public TableDataInfo list(@RequestBody SysUserDTO sysUserDTO) {
        startPage();
        List<SysUserDTO> list = sysUserService.selectUserList(sysUserDTO);
        return getDataTable(list);
    }

    @ApiOperation("获取当前用户信息")
    @GetMapping("info")
    public JsonData getCurrentUserInfo() {

        return sysUserService.getCurrentUserInfo();
    }

    @ApiOperation("根据用户id获取详细信息")
    @GetMapping("/info/{userId}")
    public JsonData getUserInfoById(@PathVariable(value = "userId", required = false) Long userId) {

        return sysUserService.getUserInfoById(userId);
    }


    @ApiOperation("根据用户id获取授权角色")
    @GetMapping("/authRole/{userId}")
    public JsonData getRolesByUserId(@PathVariable("userId") Long userId) {

        return sysUserService.getRolesByUserId(userId);
    }


    @ApiOperation("用户授权角色")
    @PutMapping("/authRole")
    public JsonData insertAuthRole(Long userId, Long[] roleIds){

        return sysUserService.insertUserAuth(userId, roleIds);
    }

    @ApiOperation("用户登录")
    @PostMapping("login")
    public JsonData login(HttpServletResponse response, @RequestBody LoginUserVo loginUserVo){

        return sysUserService.login(response,loginUserVo);
    }

}

